package com.yanqu.road.server.cmd.wingroom.message;

import com.yanqu.road.entity.servercenter.GameEditLimit;
import com.yanqu.road.pb.wingroom.WingRoomProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.manger.ForbiddenMgr;
import com.yanqu.road.server.manger.GameEditLimitMgr;
import com.yanqu.road.server.manger.wingroom.WingRoomMessageMgr;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.GameErrorCode;
import com.yanqu.road.server.protocol.GameProtocol;
import com.yanqu.road.server.protocol.Protocol;

/**
 * @author ：zfr
 * @date ：2022/3/18 1:37
 */
@Cmd(code = GameProtocol.S_WING_ROOM_CHANGE_SELF_MESSAGE_CONTENT, desc = "修改自己留言板上的留言")
public class ChangeSelfMessageContentCmd extends AbstractCommand {
    private static String content;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        WingRoomProto.ChangeSelfMessageContentReqMsg reqMsg = WingRoomProto.ChangeSelfMessageContentReqMsg.parseFrom(packet.getBytes());
        content = reqMsg.getContent();
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        WingRoomProto.ChangeSelfMessageContentRespMsg.Builder respMsg;
        //编辑限制
        GameEditLimit gameEditLimit = GameEditLimitMgr.getGameEditLimit(Protocol.S_WING_ROOM_CHANGE_SELF_MESSAGE_CONTENT);
        if(null != gameEditLimit){
            long nowTime = System.currentTimeMillis();
            if(nowTime >= gameEditLimit.getLimitEditStartTime() && nowTime < gameEditLimit.getLimitEditEndTime()){
                respMsg = WingRoomProto.ChangeSelfMessageContentRespMsg.newBuilder();
                respMsg.setRet(GameErrorCode.E_SYSTEM_NO_OPEN);
                player.sendPacket(ClientProtocol.U_WING_ROOM_CHANGE_SELF_MESSAGE_CONTENT, respMsg);
                return;
            }
        }
        /**
         * 如果被禁用 则返回系统未开放
         */
        if (ForbiddenMgr.isForbiddenCmd(player.getUserId(), Protocol.S_WING_ROOM_CHANGE_SELF_MESSAGE_CONTENT)) {
            respMsg = WingRoomProto.ChangeSelfMessageContentRespMsg.newBuilder();
            respMsg.setRet(GameErrorCode.E_SYSTEM_NO_OPEN);
            player.sendPacket(ClientProtocol.U_WING_ROOM_CHANGE_SELF_MESSAGE_CONTENT, respMsg);
            return;
        }
        respMsg = WingRoomMessageMgr.changeSelfMessageContent(player, content);
        player.sendPacket(ClientProtocol.U_WING_ROOM_CHANGE_SELF_MESSAGE_CONTENT, respMsg);
    }

    @Override
    public void sendData(GamePlayer player) {

    }
}
